<template>
  <a-modal
    :title="$t('新增商品')"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @cancel="handleCancel"
    :cancelText="$t('关闭')"
    v-drag
  >
  <template slot="footer">
    <a-button @click="handleCancel">{{$t('取消')}}</a-button>
  </template>
    <a-spin :spinning="confirmLoading">
      <div>
         <a-row :gutter="24">
           <a-col :span="6" class="top-col" @click="handleAdd(item.value)" v-for="(item, indexs) in list" :key="indexs">{{item.title}}</a-col>
         </a-row>
      </div>
    </a-spin>
    <goods-info-modal ref="modalForm" @ok="modalFormOk" />
    <coupons-modal ref="conponsForm" @ok="modalFormOk"></coupons-modal>
    <goods-info-a-coin-modal ref="aCoInModalForm" @ok="modalFormOk" />
  </a-modal>
</template>

<script>
import { postAction, httpAction } from '@/api/manage'
import pick from 'lodash.pick'
import { getAction, putAction } from '../../../api/manage'
import { initDictOptions } from '@/components/dict/JDictSelectUtil'
import GoodsInfoModal from './GoodsInfoModal'
import CouponsModal from './CouponsModal'
import GoodsInfoACoinModal from './GoodsInfoACoinModal'

export default {
  name: 'AddGoodsFirstModal',
   components: {
    GoodsInfoModal,
    CouponsModal,
    GoodsInfoACoinModal
  },
  data() {
    return {
      width: 700,
      visible: false,
      model: {},
      confirmLoading: false,
      dataForm: {
        goodsId: '',
      },
      treeData: [],
      allChildKind: [],
      goodsList:[],
      value:'',
      list:[],
    }
  },
  methods: {
    edit() {
      let that=this;
      this.visible = true
      initDictOptions('bis_goods_infor.form').then((res) => {
        if (res.success) {
          that.list=[];
          let auth = localStorage.getItem("auth").split(",");
          res.result.forEach(function(item){
            if (auth.indexOf('Form:physicalGoods:authorize') >= 0 && item.value=="1" && item.value!="13") {
              that.list.push(item);
            }
            if (auth.indexOf('Form:rechargeCoin:authorize') >= 0 && item.value=="2" && item.value!="13") {
              that.list.push(item);
            }
            if (auth.indexOf('Form:tickets:authorize') >= 0 && item.value=="3" && item.value!="13") {
              that.list.push(item);
            }
            if (auth.indexOf('Form:yearTicket:authorize') >= 0 && item.value=="4" && item.value!="13") {
              that.list.push(item);
            }
            if (auth.indexOf('Form:setMeal:authorize') >= 0 && item.value=="5" && item.value!="13") {
              that.list.push(item);
            }
            if (auth.indexOf('Form:rxb:authorize') >= 0 && item.value=="8" && item.value!="13") {
              that.list.push(item);
            }
            if (auth.indexOf('Form:coupon:authorize') >= 0 && item.value=="9" && item.value!="13") {
              that.list.push(item);
            }
            if (auth.indexOf('Form:yylmGoods:authorize') >= 0 && item.value=="10" && item.value!="13") {
              that.list.push(item);
            }
            if (auth.indexOf('Form:material:authorize') >= 0 && item.value=="11" && item.value!="13") {
              that.list.push(item);
            }
            if (auth.indexOf('Form:transferredGoods:authorize') >= 0 && item.value=="12" && item.value!="13") {
              that.list.push(item);
            }
            if (auth.indexOf('Form:rechargeACoin:authorize') >= 0 && item.value=="14") {
              that.list.push(item);
            }
          })
          //this.list = res.result
        }
      })
    },
    handleAdd(state) {
      if (state == 9) {
        this.$refs.conponsForm.add(state)
        this.$refs.conponsForm.title = this.$t('新增优惠券')
        this.$refs.conponsForm.disableSubmit = false
      } else if (state == 14) {
        this.$refs.aCoInModalForm.add(state)
        this.$refs.aCoInModalForm.title = this.$t('新增')
        this.$refs.aCoInModalForm.disableSubmit = false
      }else {
        this.$refs.modalForm.add(state)
        this.$refs.modalForm.title = this.$t('新增')
        this.$refs.modalForm.disableSubmit = false
      }
    },
    modalFormOk(){
      this.close()
      this.$emit('ok')
    },
    handleCancel() {
      this.close()
    },
    close() {
      this.visible = false
    },
  },
}
</script>
<style>
.top-col {
  text-align: center;
  height: 60px;
  line-height: 60px;
  border-radius: 5px;
  margin: 0 20px 15px 20px;
  font-size: 16px;
  color: #ffff;
  background-color: #eb5467;
}
</style>